


***Name: "Verdreht"	! Must be defined railing type name
***Code: 10007								! Must be defined identification code
                                            ! It must be also the subroutine label in GDL section


!Notes:

!B Bool       [] both option available [0] only 0 available [1] only 1 available
!I Integer    [0,15] value range 0=<p=<15, [] means unlimited value range [0] means param. not available
!D Double     [0.32,99] value range [] means unlimited value range [0] means param. not available
!M Material   [0] means param. not available
!P Pen        [0] means param. not available
!F Fill       [0] means param. not available
!T Text       [0] means param. not available
!S Font type  [0] means param. not available

***STD***         ! Must be defined standard parameters section delimiter.
                  ! Section may be empty, but parameter names and types not able to change

RailingOffset:     D [-1.0,1.0]=-0.005 ! railing offset to edge of stair value: positive value means inside
RailingUpPos:      D [0.3, 10.0]=0.9    ! railing top position above step level
RailingDnPos:      D [0.0, 10.0]=0.1     ! railing bottom position above step level
ColumnOffset:      D [-0.8,0.8]=0    ! column offset to railing line value: positive value means inside
ColumnOffsetUp:    D [0,0.5]=0       ! column horizontal overhang up
ColumnOffsetDn:    D [0,0.5]=0       ! column horizontal overhang down
FirstColumnOffset: D [0,3]=0.1       ! first column offset along the railing
CnPlacementType:   I [1,3]=1         ! no Column, closest to, on every Tread, pieces: 0,1,2,3
ClosestToDistance: D [0.02,3.2]=0.80  ! distance of columns to each other
SnapToCorners:     B [0,1]=1            ! 1=columns  at segment ends

***ADD***         ! Must be defined additional parameters section delimiter (section may be empty)

res:"Hohe Aufl.gen" B [0,1]=0
ac1:"Sttzenbreite" D [0.01,0.1]=0.025        ! column width
bc1:"Sttzentiefe" D [0.01,0.1]=0.005        ! column depth
r1:"Rhrenradius" D [0.01,0.1]=0.0075         ! radius of field tubes
vdft:"Vert. Abstand" D [0.1,1]=0.1    ! vert. dist. of field tubes ("closest to" principle)
mat_r:"Gelndermat." M []=10     ! railing material
mat_c:"Sttzenmaterial" M []=47      ! column material




***GDL***         ! Must be defined section delimiter for railing GDL subroutine







!================================================ GDL OF RAILING
!================================================================


10007:                            ! railing code

if res =0 then resol 8 else resol 36

wr=4*r1      		      	! width of rail section
hr=0.66*wr         		! height of rail section
mat_f=mat_c			! field tube material




IF current_side=0 then


    !*********************************** left side railing
    !******************************************************

voct=segm_l[current_segment][8]             ! vertical oversize of columns at the top


    ! ************************* rail

    h1=segm_l[current_segment][12]             ! height of railing
    h2=segm_l[current_segment][11]             ! height of bottom tube axis
    h3=h1-0.12

    nr=segm_l[current_segment][2]   !number of railing coordinates
    n=segm_l[current_segment][6]    !number of columns

    fqw1=segm_l[current_segment][3]  !first point index of current segment
    fqwn=segm_l[current_segment][3]+segm_l[current_segment][2]-1  !last point index of current segment



    !********************* railing

    material mat_r


    !plus one point for tube direction at the beginning & in the end

    x1=rail_l [fqw1][1]-(rail_l [fqw1+1][1]-rail_l [fqw1][1])
    y1=rail_l [fqw1][2]-(rail_l [fqw1+1][2]-rail_l [fqw1][2])
    z1=rail_l [fqw1][3]-(rail_l [fqw1+1][3]-rail_l [fqw1][3])

    xn=rail_l [fqwn][1]+(rail_l [fqwn][1]-rail_l [fqwn-1][1])
    yn=rail_l [fqwn][2]+(rail_l [fqwn][2]-rail_l [fqwn-1][2])
    zn=rail_l [fqwn][3]+(rail_l [fqwn][3]-rail_l [fqwn-1][3])



    ff=wr/0.08     ! railing section resizing factors
    fff=hr/0.035

    for i=fqw1 to fqwn
        put rail_l [i][1], rail_l [i][2], rail_l [i][3], 0
    next i


    tube 22, nr+2, 1+2+16+32,
        0.0,            -0.015625*fff,     1,
       -0.031225*ff,    -0.015625*fff,     1,
       -0.035491*ff,    -0.011532*fff,     1,
       -0.038878*ff,    -0.00588*fff,      1,
       -0.04*ff,         0.0,              1,
       -0.038878*ff,     0.00588*fff,      1,
       -0.035491*ff,     0.011532*fff,     1,
       -0.031225*ff,     0.015625*fff,     1,
       -0.022446*ff,     0.017761*fff,     1,
       -0.013524*ff,     0.019192*fff,     1,
       -0.004518*ff,     0.01991*fff,      1,
        0.004518*ff,     0.01991*fff,      1,
        0.013524*ff,     0.019192*fff,     1,
        0.022446*ff,     0.017761*fff,     1,
        0.031225*ff,     0.015625*fff,     1,
        0.035491*ff,     0.011532*fff,     1,
        0.038878*ff,     0.00588*fff,      1,
        0.04*ff,         0.0,              1,
        0.038878*ff,    -0.00588*fff,      1,
        0.035491*ff,    -0.011532*fff,     1,
        0.031225*ff,    -0.015625*fff,     1,
        0.0,            -0.015625*fff,     1,

        x1, y1, z1, 0,
        get (nsp),
        xn, yn, zn, 0



    !*********************** columns

    material mat_c

    for i=segm_l[current_segment][7] to segm_l[current_segment][7]+n-1

        c1=column_l[i][4]                  ! column point index

        hc1=rail_l[c1][3]-column_l[i][3]   ! height of column


        if c1=1 then

            xx1=rail_l[c1+1][1]-rail_l[c1][1]
            yy1=rail_l[c1+1][2]-rail_l[c1][2]

        else

            xx1=(rail_l[c1][1]-rail_l[c1-1][1])
            yy1=(rail_l[c1][2]-rail_l[c1-1][2])

        endif

        if c1=segm_l[current_segment][2] then

            xx2=rail_l[c1][1]-rail_l[c1-1][1]
            yy2=rail_l[c1][2]-rail_l[c1-1][2]

        else

            xx2=(rail_l[c1+1][1]-rail_l[c1][1])
            yy2=(rail_l[c1+1][2]-rail_l[c1][2])

        endif

        if xx1=0 then        ! angle of the previous part
            aa1=90
        else
            aa1=atn(yy1/xx1)
        endif

        aa=aa1               ! rotating angle of column

        if xx1<0 then aa=180+aa1

        addx column_l[i][1]
        addy column_l[i][2]
        addz column_l[i][3]

        rotz aa
        rotz 90

        s=24

        for j=1 to s step 1
            put 0, 0, 0.02+0.12/s*j, 90/s*j
        next j


        tube 4, 6+s, 1+2+16+32,
            -bc1, -ac1, 0,
             bc1, -ac1, 0,
             bc1,  ac1, 0,
            -bc1,  ac1, 0,

             0, 0, -0.2, 0,
             0, 0, -0.1, 0,
             0, 0, 0.02, 0,

             get (nsp),

             0, 0, 0.140, 90,
             0, 0, hc1+voct, 90,
             0, 0, hc1+voct+1, 90

        del 3+2


    next i



    !*********************** longitudinal tubes

    material mat_f

    r2=r1

    aa=0

    d=int((h3-h2)/vdft)
    if d+1-int((h3-h2)/vdft)<0.5 then d=d+1   ! "closest to vdft"

    dd=(h3-h2)/d

    res=8                 ! resol of tube section
    aa=360/res

    if n<2 then

        c1= fqw1                  ! first rail point from railing coordinates
        c2= fqwn                 ! last rail point from railing coordinates

	    for kk=1 to d+1

	        for i=1 to res
	            aa1=(i-1)*aa
	            put r2*sin(aa1), r2*cos(aa1), 1
	        next i

	        for i=c1 to c2
	            put rail_l [i][1], rail_l [i][2], rail_l [i][3]-h1+h2, 0
	        next i

	        tube res, c2-c1+1+2, 0,
	            get (res*3),

	            x1, y1, z1, 0,
	            get (nsp),
	            xn, yn, zn, 0

	         addz dd

	    next kk

    	del d+1

    else

        xvxv=segm_l[current_segment][7]
        xvxvx=segm_l[current_segment][7]+n-1

        c1=column_l[xvxv][4]   ! first column point from railing coordinates
        c2=column_l[xvxvx][4]  ! last column point from railing coordinates

    for kk=1 to d+1

        for i=1 to res
            aa1=(i-1)*aa
            put r2*sin(aa1), r2*cos(aa1), 1
        next i

        for i=c1 to c2
            put rail_l [i][1], rail_l [i][2], rail_l [i][3]-h1+h2, 0
        next i

        tube res, c2-c1+1+2, 0,
            get (res*3),

            rail_l[c1][1]-(rail_l[c1+1][1]-rail_l[c1][1]), rail_l[c1][2]-(rail_l[c1+1][2]-rail_l[c1][2]), rail_l[c1][3]-(rail_l[c1+1][3]-rail_l[c1][3]), 0,
            get (nsp),
            rail_l[c2][1]+(rail_l[c2][1]-rail_l[c2-1][1]), rail_l[c2][2]+(rail_l[c2][2]-rail_l[c2-1][2]), rail_l[c2][3]+(rail_l[c2][3]-rail_l[c2-1][3]), 0

         addz dd

    next kk

    del d+1


    endif


    for kk=1 to d+1

        for i=1 to res
            aa1=(i-1)*aa
            put r2*sin(aa1), r2*cos(aa1), 1
        next i

        for i=c1 to c2
            put rail_l [i][1], rail_l [i][2], rail_l [i][3]-h1+h2, 0
        next i

        tube res, c2-c1+1+2, 0,
            get (res*3),

            rail_l[c1][1]-(rail_l[c1+1][1]-rail_l[c1][1]), rail_l[c1][2]-(rail_l[c1+1][2]-rail_l[c1][2]), rail_l[c1][3]-(rail_l[c1+1][3]-rail_l[c1][3]), 0,
            get (nsp),
            rail_l[c2][1]+(rail_l[c2][1]-rail_l[c2-1][1]), rail_l[c2][2]+(rail_l[c2][2]-rail_l[c2-1][2]), rail_l[c2][3]+(rail_l[c2][3]-rail_l[c2-1][3]), 0

         addz dd

    next kk

    del d+1


ELSE


    !*********************************** right side railing
    !******************************************************

voct=segm_r[current_segment][8]             ! vertical oversize of columns at the top


    ! ************************* rail


    h1=segm_r[current_segment][12]             ! height of railing
    h2=segm_r[current_segment][11]             ! height of bottom tube axis
    h3=h1-0.12

    nr=segm_r[current_segment][2]   !number of railing coordinates
    n=segm_r[current_segment][6]    !number of columns

    fqw1=segm_r[current_segment][3]  !first point index of current segment
    fqwn=segm_r[current_segment][3]+segm_r[current_segment][2]-1  !last point index of current segment




    material mat_r


    !plus one point for tube direction at the beginning & in the end

    x1=rail_r [fqw1][1]-(rail_r [fqw1+1][1]-rail_r [fqw1][1])
    y1=rail_r [fqw1][2]-(rail_r [fqw1+1][2]-rail_r [fqw1][2])
    z1=rail_r [fqw1][3]-(rail_r [fqw1+1][3]-rail_r [fqw1][3])

    xn=rail_r [fqwn][1]+(rail_r [fqwn][1]-rail_r [fqwn-1][1])
    yn=rail_r [fqwn][2]+(rail_r [fqwn][2]-rail_r [fqwn-1][2])
    zn=rail_r [fqwn][3]+(rail_r [fqwn][3]-rail_r [fqwn-1][3])



    ff=wr/0.08     ! railing section resizing factors
    fff=hr/0.035

    for i=fqw1 to fqwn
        put rail_r [i][1], rail_r [i][2], rail_r [i][3], 0
    next i


    tube 22, nr+2, 1+2+16+32,
        0.0,            -0.015625*fff,     1,
       -0.031225*ff,    -0.015625*fff,     1,
       -0.035491*ff,    -0.011532*fff,     1,
       -0.038878*ff,    -0.00588*fff,      1,
       -0.04*ff,         0.0,              1,
       -0.038878*ff,     0.00588*fff,      1,
       -0.035491*ff,     0.011532*fff,     1,
       -0.031225*ff,     0.015625*fff,     1,
       -0.022446*ff,     0.017761*fff,     1,
       -0.013524*ff,     0.019192*fff,     1,
       -0.004518*ff,     0.01991*fff,      1,
        0.004518*ff,     0.01991*fff,      1,
        0.013524*ff,     0.019192*fff,     1,
        0.022446*ff,     0.017761*fff,     1,
        0.031225*ff,     0.015625*fff,     1,
        0.035491*ff,     0.011532*fff,     1,
        0.038878*ff,     0.00588*fff,      1,
        0.04*ff,         0.0,              1,
        0.038878*ff,    -0.00588*fff,      1,
        0.035491*ff,    -0.011532*fff,     1,
        0.031225*ff,    -0.015625*fff,     1,
        0.0,            -0.015625*fff,     1,

        x1, y1, z1, 0,
        get (nsp),
        xn, yn, zn, 0



    !*********************** columns

    material mat_c

    for i=segm_r[current_segment][7] to segm_r[current_segment][7]+n-1

        c1=column_r[i][4]                  ! column point index

        hc1=rail_r[c1][3]-column_r[i][3]   ! height of column


        if c1=1 then

            xx1=rail_r[c1+1][1]-rail_r[c1][1]
            yy1=rail_r[c1+1][2]-rail_r[c1][2]

        else

            xx1=(rail_r[c1][1]-rail_r[c1-1][1])
            yy1=(rail_r[c1][2]-rail_r[c1-1][2])

        endif

        if c1=segm_r[current_segment][2] then

            xx2=rail_r[c1][1]-rail_r[c1-1][1]
            yy2=rail_r[c1][2]-rail_r[c1-1][2]

        else

            xx2=(rail_r[c1+1][1]-rail_r[c1][1])
            yy2=(rail_r[c1+1][2]-rail_r[c1][2])

        endif


        if xx1=0 then        ! angle of the previous part
            aa1=90
        else
            aa1=atn(yy1/xx1)
        endif

        aa=aa1               ! rotating angle of column

        if xx1<0 then aa=180+aa1

        addx column_r[i][1]
        addy column_r[i][2]
        addz column_r[i][3]

        rotz aa
        rotz 90

        s=24

        for j=1 to s step 1
            put 0, 0, 0.02+0.12/s*j, 90/s*j
        next j


        tube 4, 6+s, 1+2+16+32,
            -bc1, -ac1, 0,
             bc1, -ac1, 0,
             bc1,  ac1, 0,
            -bc1,  ac1, 0,

             0, 0, -0.2, 0,
             0, 0, -0.1, 0,
             0, 0, 0.02, 0,

             get (nsp),

             0, 0, 0.140, 90,
             0, 0, hc1+voct, 90,
             0, 0, hc1+voct+1, 90

        del 3+2


    next i



    !*********************** longitudinal tubes

    material mat_f

    r2=r1

    aa=0

    d=int((h3-h2)/vdft)
    if d+1-int((h3-h2)/vdft)<0.5 then d=d+1   ! "closest to vdft"

    dd=(h3-h2)/d

    res=8                 ! resol of tube section
    aa=360/res

    if n<2 then

        c1= fqw1                  ! first rail point from railing coordinates
        c2= fqwn                 ! last rail point from railing coordinates

	    for kk=1 to d+1

	        for i=1 to res
	            aa1=(i-1)*aa
	            put r2*sin(aa1), r2*cos(aa1), 1
	        next i

	        for i=c1 to c2
	            put rail_r [i][1], rail_r [i][2], rail_r [i][3]-h1+h2, 0
	        next i

	        tube res, c2-c1+1+2, 0,
	            get (res*3),

	            x1, y1, z1, 0,
	            get (nsp),
	            xn, yn, zn, 0

	         addz dd

	    next kk

    	del d+1

    else

        xvxv=segm_r[current_segment][7]
        xvxvx=segm_r[current_segment][7]+n-1

        c1=column_r[xvxv][4]   ! first column point from railing coordinates
        c2=column_r[xvxvx][4]  ! last column point from railing coordinates

    for kk=1 to d+1

        for i=1 to res
            aa1=(i-1)*aa
            put r2*sin(aa1), r2*cos(aa1), 1
        next i

        for i=c1 to c2
            put rail_r [i][1], rail_r [i][2], rail_r [i][3]-h1+h2, 0
        next i

        tube res, c2-c1+1+2, 0,
            get (res*3),

            rail_r[c1][1]-(rail_r[c1+1][1]-rail_r[c1][1]), rail_r[c1][2]-(rail_r[c1+1][2]-rail_r[c1][2]), rail_r[c1][3]-(rail_r[c1+1][3]-rail_r[c1][3]), 0,
            get (nsp),
            rail_r[c2][1]+(rail_r[c2][1]-rail_r[c2-1][1]), rail_r[c2][2]+(rail_r[c2][2]-rail_r[c2-1][2]), rail_r[c2][3]+(rail_r[c2][3]-rail_r[c2-1][3]), 0

         addz dd

    next kk

    del d+1

    endif






ENDIF

1000744:

del top


RETURN
